package com.sumer.proxy.jdk.proxy;

import com.sumer.proxy.jdk.domain.Student;
import com.sumer.proxy.jdk.service.StudentService;

/**
 * 静态代理类
 */
public class StudentProxy implements StudentService {

    private StudentService studentService;

    private Transaction transaction;

    public StudentProxy(StudentService studentService, Transaction transaction) {
        this.studentService = studentService;
        this.transaction = transaction;
    }

    @Override
    public void add(Student student) {
        transaction.begin();
        studentService.add(student);
        transaction.commit();
    }

    @Override
    public Student get(Integer id) {
        return studentService.get(id);
    }
}
